package com.solo.eggsolo.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.solo.eggsolo.common.bean.JsonResult;
import com.solo.eggsolo.common.bean.Pager;
import com.solo.eggsolo.entity.Dailylog;
import com.solo.eggsolo.entity.SongSingerContact;
import com.solo.eggsolo.service.SongSingerContactService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @author acer
 *
 */
@RestController
@RequestMapping("/song-singer")
@Api(tags = "歌手歌曲连接")
public class SongSingerContactController {
	@Autowired
	private SongSingerContactService songSingerContactService;

	@ApiOperation("获取所有歌手歌曲联系表的信息")
	@RequestMapping(value = "/list", method = { RequestMethod.GET })
	public Pager<SongSingerContact> list(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "10") Integer size) {
		Pager<SongSingerContact> pager = new Pager<>(page, size);

		List<SongSingerContact> list = songSingerContactService.list(pager);
		int total = songSingerContactService.count(pager);
		pager.setData(list);
		pager.setTotal(total);
		pager.setCode(200);

		return pager;
	}

	@ApiOperation("根据歌手歌曲联系表id查询信息")
	@RequestMapping(value = "/findById", method = { RequestMethod.GET })
	public JsonResult findById(Integer id) {

		JsonResult result = new JsonResult(500, Boolean.FALSE, "查询失败");
		SongSingerContact songSingerContact = songSingerContactService.findById(id);

		if (songSingerContact != null) {
			result = new JsonResult(200, Boolean.TRUE, "查询成功", songSingerContact);
		}

		return result;
	}
	
	@ApiOperation("根据歌手id查询其歌曲")
	@RequestMapping(value = "/findSongBySingId", method = { RequestMethod.GET })
	public JsonResult findSongBySingId(Integer singerId) {

		JsonResult result = new JsonResult(500, Boolean.FALSE, "查询失败");
		List<SongSingerContact> list = songSingerContactService.findSongBySingId(singerId);

		if (list != null) {
			result = new JsonResult(200, Boolean.TRUE, "查询成功", list);
		}

		return result;
	}

	@ApiOperation("增加歌手歌曲联系表的信息")
	@RequestMapping(value = "/add", method = { RequestMethod.POST })
	public JsonResult add(SongSingerContact songSingerContact) {
		JsonResult result = new JsonResult(500, Boolean.FALSE, "新增失败");

		boolean ret = songSingerContactService.add(songSingerContact);
		if (ret) {
			result = new JsonResult(200, Boolean.TRUE, "新增成功");
		}
		return result;
	}

	@ApiOperation("根据歌手歌曲联系表id编辑信息")
	@RequestMapping(value = "/edit", method = { RequestMethod.POST })
	public JsonResult edit(SongSingerContact songSingerContact) {
		JsonResult result = new JsonResult(Boolean.FALSE, "修改失败");
		boolean ret = songSingerContactService.edit(songSingerContact);
		if (ret) {
			result = new JsonResult(Boolean.TRUE, "修改成功");
		}
		return result;
	}

	@ApiOperation("根据歌手歌曲联系表id删除信息")
	@RequestMapping(value = "/delete", method = { RequestMethod.POST })
	public JsonResult delete(SongSingerContact songSingerContact) {
		JsonResult result = new JsonResult(500, Boolean.FALSE, "删除失败");

		List<SongSingerContact> list = new ArrayList<SongSingerContact>();
		list.add(songSingerContact);

		boolean ret = songSingerContactService.deleteByIds(list);
		if (ret) {
			result = new JsonResult(200, Boolean.TRUE, "删除成功");
		}

		return result;
	}
}
